use crate::models::{PageItem, PageStagingItem};
use crate::utils::{git, Data};

#[test]
fn test_load_config() {
    let _ = Data::load_config("./src/tests/example.json").expect("load config error");

    assert!(true);
}

#[test]
fn test_clone_with_other_name() {
    let folder_name = "hello";
    if std::path::Path::new(folder_name).exists() {
        std::fs::remove_dir_all(folder_name).expect("remove dir error");
    }
    println!("begin clone");

    git::clone(
        "git@gitee.com:hanshu_alan/uni-components.git",
        "master",
        Some(folder_name),
    )
    .expect("clone error");

    assert!(true);
}
#[test]
fn test_clone_with_no_name() {
    if std::path::Path::new("uni-components").exists() {
        std::fs::remove_dir_all("uni-components").expect("remove dir error");
    }
    println!("begin clone");

    git::clone(
        "git@gitee.com:hanshu_alan/uni-components.git",
        "master",
        None,
    )
    .expect("clone error");

    assert!(true);
}
#[test]
fn test_clone_with_multi_folders() {
    let multi_folders = "projects/temp1";
    if std::path::Path::new(multi_folders).exists() {
        std::fs::remove_dir_all(multi_folders).expect("remove dir error");
    }
    println!("begin clone");

    git::clone(
        "git@gitee.com:hanshu_alan/uni-components.git",
        "master",
        Some(multi_folders),
    )
    .expect("clone error");

    assert!(true);
}
#[test]
fn test_get_default_git_project_name() {
    assert_eq!(
        git::get_default_git_project_name("git@gitee.com:hanshu_alan/uni-components.git").unwrap(),
        "uni-components".to_string()
    );
}

#[test]
fn test_page_item_to_page_staging_item() {
    let page_item = PageItem {
        key: "home".to_string(),
        vue_path: "index/index.vue".to_string(),
    };

    let target_page_staging_item = PageStagingItem {
        key: "home".to_string(),
        vue_path: "index/index.vue".to_string(),
        module_path: "mixins/index/index.vue".to_string(),
        module_folder_path: "mixins/index".to_string(),
        module_components_staging_path: "mixins/index/componentsMixins.staging".to_string(),
        module_components_path: "mixins/index/componentsMixins.js".to_string(),
        module_methods_staging_path: "mixins/index/methodsMixins.staging".to_string(),
        module_methods_path: "mixins/index/methodsMixins.js".to_string(),
    };

    assert_eq!(
        PageStagingItem::try_from(&page_item, "mixins").expect("to page_staging_item error"),
        target_page_staging_item
    );
}
